package com.freesky.web.manager.controller;

import com.freesky.common.pojo.DataTablesResult;
import com.freesky.common.utils.reponse.JSONResponse;
import com.freesky.common.utils.reponse.JSONResponseDiretor;
import com.freesky.common.dao.entity.Thanks;
import com.freesky.web.manager.service.ThanksService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author Freesky
 */
@RestController
@Api(description= "捐赠管理")
public class ThanksController {

    @Autowired
    private ThanksService thanksService;

    @RequestMapping(value = "/thanks/list",method = RequestMethod.GET)
    @ApiOperation(value = "获取捐赠列表")
    public DataTablesResult getThanksList(){

        DataTablesResult result=thanksService.getThanksList();
        return result;
    }

    @RequestMapping(value = "/thanks/count",method = RequestMethod.GET)
    @ApiOperation(value = "获取捐赠列表总数")
    public JSONResponse getThanksCount(){
        return  thanksService.countThanks();
    }

    @RequestMapping(value = "/thanks/add",method = RequestMethod.POST)
    @ApiOperation(value = "添加捐赠")
    public JSONResponse addThanks(@ModelAttribute Thanks thanks){

       return thanksService.addThanks(thanks);
    }

    @RequestMapping(value = "/thanks/update",method = RequestMethod.POST)
    @ApiOperation(value = "编辑捐赠")
    public JSONResponse updateThanks(@ModelAttribute Thanks thanks){
        return  thanksService.updateThanks(thanks);
    }

    @RequestMapping(value = "/thanks/del/{ids}",method = RequestMethod.DELETE)
    @ApiOperation(value = "删除捐赠")
    public JSONResponse delThanks(@PathVariable int[] ids){
        for(int id:ids){
            thanksService.deleteThanks(id);
        }
        return JSONResponseDiretor.buildSuccessJSONResponse(null);
    }

    @RequestMapping(value = "/thanks/{id}",method = RequestMethod.GET)
    @ApiOperation(value = "通过id获取捐赠")
    public JSONResponse getThanks(@PathVariable int id){

        return thanksService.getThankById(id);
    }
}
